package com.campus.shop.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Description:包装统一返回结果类
 * @Author: xr
 * @Date: 2023/3/6 16:28
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result {
    private int code;
    private String msg;
    private Object data;

    public Result(Integer code, String msg){
        this.code = code;
        this.msg = msg;
    }
    //操作成功返回
    public static Result success(Object data) {
        return new Result(200, "操作成功", data);
    }

    //重载操作成功返回
    public static Result success(String msg, Object data) {
        return new Result(200, msg, data);
    }

    //重载操作成功
    public static Result success() {
        return new Result(200, "操作成功", null);
    }

    //数据库操作失败
    public static Result sqlError(){
        return new Result(500,"数据库修改失败",null);
    }

    //操作失败返回
    public static Result error(int code, String msg) {
        return new Result(code, msg, null);
    }

    public static Result error(){
        return new Result(500,"操作失败",null);
    }

    //报错返回
    public static Result error(Errors errors) {
        return new Result(errors.getCode(), errors.getMsg(), null);
    }
    //报错返回
    public static Result error(String msg){
        return new Result(500, msg);
    }





}
